<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px">
      <el-form-item label="年级" prop="year">
        <el-select v-model="queryParams.year" clearable filterable placeholder="请选择年级">
          <el-option
            v-for="dict in dict.type.year_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="学期" prop="semId">
        <el-select v-model="queryParams.semId" filterable clearable placeholder="请选择学期">
          <el-option
            v-for="item in semsterList"
            :key="item.id"
            :label="item.title"
            :value="item.id"
            size="small">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="年" prop="year">
        <el-date-picker clearable size="small" style="width: 200px"
                v-model="queryParams.date"
                type="year"
                placeholder="选择年">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="月" prop="year">
        <el-date-picker clearable size="small" style="width: 200px"
            v-model="queryParams.date"
            type="month"
            placeholder="选择月份">
        </el-date-picker>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <div class="tright"><el-radio-group v-model="sortkey" @change="echartdata">
      <el-radio-button label="升序"></el-radio-button>
      <el-radio-button label="降序"></el-radio-button>
    </el-radio-group></div>
    <div ref="suggestinfo" style="height: 420px" />


  </div>
</template>

<script>
import { selectSemster } from '@/api/base/semster'
import echarts from "echarts";
export default {
  name: "gzt",
  dicts: ['year_type'],
  data() {
    return {
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
      },
      // 学期数据
      semsterList: [],
      suggestinfo:null,
      sortkey:'升序',
      chartsdata:[],//表数据
    };
  },
  created() {
    this.getSemster();

    // this.openLoading();
  },
  mounted() {
    this.getList();
  },
  methods: {
    /**建议接口**/
    async getList(){
      try {
        // this.loading.close();
        this.suggestinfo=echarts.init(this.$refs.suggestinfo);
        this.chartsdata=[{name:'小一班',value:'120'},{name:'小二班',value:'200'},{name:'小三班',value:'150'},{name:'小四班',value:'80'},{name:'小一班',value:'70'},{name:'小一班',value:'70'},{name:'小二班',value:'200'},{name:'小三班',value:'150'}]
        this.echartdata();

      }catch (e) {
        console.log(e)
      }
    },
    echartdata(){
      let that=this
      //判断升序降序处理数据
      if(this.sortkey=='升序'){
        this.chartsdata=this.chartsdata.sort(function(a,b){
          return a.value-b.value
        })
      }else{
        this.chartsdata=this.chartsdata.sort(function(a,b){
          return b.value-a.value
        })
      }
      //判断超过20条数据出现滚动条
      let zoomdata=[];
      if(this.chartsdata.length>20){
        zoomdata=[{
          type: 'inside',
          show: true,
          xAxisIndex: [0],
          start: 0,//默认为1
          end:80,//默认为100
        },
          {
            type: 'slider',//slider表示有滑动块的，inside表示内置的
            start: 0,//默认为0  可设置滚动条从在后进行展示
            end: 50,//默认为100
            show: true,
            xAxisIndex: [0],
            handleSize: 0,//滑动条的 左右2个滑动条的大小
            height: 12,//组件高度
            left: '5%', //左边的距离
            right: '5%',//右边的距离
            bottom: -2,//右边的距离
            borderColor: "#f5f4f4",
            fillerColor: '#d7d5d5',
            backgroundColor: '#f5f4f4',//两边未选中的滑动条区域的颜色
            // showDataShadow: false,//是否显示数据阴影 默认auto
            showDetail: false,//即拖拽时候是否显示详细数值信息 默认true
            realtime: true, //是否实时更新
            filterMode: 'filter',
            handleStyle: {
              borderRadius: '20',
            },
          }]
      }
      this.suggestinfo.setOption({
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'shadow'
          }
        },
        xAxis: {
          type: 'category',
          data:that.chartsdata.map(item=>{return item.name}),
          axisLabel: { interval: 0, rotate: 30 }
        },
        dataZoom: zoomdata,
        yAxis: {
          type: 'value',
          name:'投诉数量',
          axisLabel: {
            formatter: '{value} 个'
          },
        },
        series: [
          {
            data:that.chartsdata,
            type: 'bar',
            showBackground: false,
            barWidth:20,
            itemStyle: {
              normal: {
                //这里是颜色
                color: '#1088f8'
              }
            }
          }
        ]
      })
    },
    /**学期*/
    async getSemster(){
      try {
        const { rows }=await selectSemster();
        this.semsterList =rows;
      }catch (e) {
        console.log(e)
      }
    },
    // 打开加载层
    openLoading() {
      this.loading = this.$loading({
        lock: true,
        text: "拼命读取中",
        spinner: "el-icon-loading",
        background: "rgba(0, 0, 0, 0.7)",
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
  }
};
</script>
<style lang="scss" scoped>
.tright{
  text-align:right
}
</style>
